<template>
  <div class="login_container">
    <div class="login_box">
      <h2>用户注册</h2>
      <!-- 登录表单 -->
      <el-form
        ref="loginFormRef"
        :model="loginForm"
        class="login_form"
        :rules="rules"
        label-width="80px"
      >
        <!-- 用户名 -->
        <el-form-item label="用户名" prop="userId">
          <el-input
            v-model="loginForm.userId"
            placeholder="请输入用户名"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input
            v-model="loginForm.password"
            placeholder="请输入密码"
          ></el-input>
        </el-form-item>
        <el-form-item label="确认密码" prop="rePassword">
          <el-input
            v-model="loginForm.rePassword"
            placeholder="请再次确认密码"
          ></el-input>
        </el-form-item>
        <el-button @click="quit">取 消</el-button>
        <el-button type="primary" style="margin: 0 0 10px 5px;"
          >确 定</el-button
        >
      </el-form>
    </div>
  </div>
</template>
<script>
// import register from "./register.vue";
export default {
  components: {
    // register
  },
  data() {
    return {
      // 表单数据
      loginForm: {
        userId: "",
        password: "",
        rePassword: ""
      },
      rules: {
        userId: [
          { required: true, message: "用户名不能为空", trigger: "blur" }
        ],
        password: [
          { required: true, message: "密码不能为空", trigger: "blur" }
        ],
        rePassword: [{ required: true, message: "请确认密码", trigger: "blur" }]
      }
    };
  },
  methods: {
    // 重置表单
    resetLoginForm() {
      this.$refs.loginFormRef.resetFields();
    },
    // 登录
    login() {
      this.$refs.loginFormRef.validate(async value => {
        if (!value) return;
        this.$router.push("/Home");
        const { data: res } = await this.$http.post(
          "/user/login",
          this.loginForm
        );
        console.log(res);
      });
    },
    quit() {
      this.$router.push("/login");
    }
  }
};
</script>

<style lang="less" scoped>
.login_container {
  height: 100%;
  background-color: #0b3660;
}

.login_box {
  height: 320px;
  width: 450px;
  border-radius: 5px;
  background-color: #fff;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}
.login_form {
  position: absolute;
  width: 100%;
  padding: 0 20px;
  box-sizing: border-box;
}
.btn {
  display: flex;
  justify-content: center;
}
</style>
